<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <!--
        <a-button type="primary" v-auth="'wyf:wyf_houses:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        -->
        <j-upload-button type="primary" v-auth="'wyf:wyf_houses_wait_review:importExcel'" preIcon="ant-design:import-outlined" @click="onImportXls"
          >导入</j-upload-button
        >
        <a-button :ghost="true" v-auth="'wyf:wyf_houses_wait_review:importExcel'" type="primary" preIcon="ant-design:download" @click="onDownloadXls">
          模板下载
        </a-button>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <!--字段回显插槽-->
      <template #bodyCell="{ column, record, index, text }">
        <template v-if="column.dataIndex === 'jwh'">
          <!--省市区字段回显插槽-->
          {{ getAreaTextByCode(text) }}
        </template>
      </template>
    </BasicTable>
    <!--编辑抽屉-->
    <ApproveDrawer @register="registerDrawer" @success="handleSuccess" />
    <!--详情抽屉-->
    <DetailDrawer @register="registerDetailDrawer" />
  </div>
</template>

<script lang="ts" name="wyf-wyfHouses" setup>
  import { ref, reactive, computed, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useDrawer } from '/@/components/Drawer';
  import { columns, searchFormSchema } from './pending.data';
  import { list, getImportUrl, getExportUrl } from './pending.api';
  import { useUserStore } from '/@/store/modules/user';
  import { getAreaTextByCode } from '/@/components/Form/src/utils/Area';
  import ApproveDrawer from '../approved/components/ApprovedDrawer.vue';
  import { getDownloadUrl } from '@/views/house/approved/approved.api';
  import DetailDrawer from '../approved/components/DetailDrawer.vue';
  const queryParam = reactive<any>({});
  const userStore = useUserStore();
  //注册drawer
  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerDetailDrawer, { openDrawer: openDetailDrawer }] = useDrawer();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls, onDownloadXls } = useListPage({
    tableProps: {
      rowKey: 'id',
      title: '待审核',
      api: list,
      columns,
      canResize: false,
      formConfig: {
        //labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [],
        fieldMapToTime: [],
      },
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        let xzqh = '';
        if (params.xzqh) {
          let xzqy = params.xzqh.split(',');
          xzqh = xzqy[xzqy.length - 1];
        }

        return Object.assign(params, { xzqh });
      },
      scroll: { x: 800 },
      bordered: false,
    },
    exportConfig: {
      name: '房源表',
      url: getExportUrl,
      params: queryParam,
    },
    importConfig: {
      url: getImportUrl,
      success: handleSuccess,
    },
    downloadConfig: {
      name: '嘉兴监管平台房源导入模板',
      url: getDownloadUrl,
    },
  });

  const [registerTable, { reload }] = tableContext;

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    openDrawer(true, {
      record,
      isUpdate: true,
      isFysh:true,
      showFooter: true,
      type: 'pending',
    });
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    reload();
  }
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      },
      {
        label: '审核',
        onClick: handleEdit.bind(null, record),
        auth: 'wyf:wyf_house_reviews:edit',
      },
    ];
  }
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    openDetailDrawer(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
  }
</script>

<style lang="less" scoped>
  :deep(.ant-picker),
  :deep(.ant-input-number) {
    width: 100%;
  }
</style>
